package com.bawei.mdm2207alast.mine.ask

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Divider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.bawei.mdm2207alast.R
import com.bawei.mdm2207alast.common.BaseTitle
import com.bawei.mdm2207alast.common.UserCard
import com.bawei.mdm2207alast.model.db.AskEntity
import com.google.gson.Gson
import com.tencent.mmkv.MMKV

/**
 * 作者：赵亮
 * 时间：2024/12/24 15:57
 * 功能：请假详情页
 */
@Composable
fun AskDetailPage(navController: NavController = rememberNavController(), json: String = "") {

    val askEntity = Gson().fromJson(json, AskEntity::class.java)

    Column {

        BaseTitle(navController = navController, title = "请假详情")

        Column(
            verticalArrangement = Arrangement.spacedBy(10.dp),
            modifier = Modifier.padding(start = 15.dp, end = 15.dp, top = 25.dp)
        ) {
            // 申报人信息
            Text(text = "申报人信息", color = Color.Blue)
            UserCard(navController = navController, mmkv = MMKV.defaultMMKV())

            // 请假详情
            Text(text = "请假详情", color = Color.Blue, modifier = Modifier.padding(top = 25.dp))
            Text(text = "请假方式：${askEntity.type}")
            Text(text = "开始时间：${askEntity.start}")
            Text(text = "结束时间：${askEntity.end}")
            Text(text = "请假原因：${askEntity.reason}")

            // 审批状态
            Row {
                Column(
                    modifier = Modifier.padding(start = 20.dp),
                    horizontalAlignment = Alignment.CenterHorizontally
                ) {
                    Image(
                        modifier = Modifier
                            .size(30.dp)
                            .clip(CircleShape),
                        painter = painterResource(id = R.drawable.profile_picture),
                        contentDescription = null
                    )
                    Box(
                        modifier = Modifier
                            .width(1.dp)
                            .height(20.dp)
                            .background(color = Color.Gray)
                    )
                    var status = R.drawable.status1
                    if (askEntity.status == "同意") {
                        status = R.drawable.status2
                    } else if (askEntity.status == "拒绝"){
                        status = R.drawable.status3
                    }
                    Image(
                        modifier = Modifier.size(25.dp),
                        painter = painterResource(id = status),
                        contentDescription = null
                    )
                }
                Column(modifier = Modifier.padding(start = 10.dp)) {
                    Text(text = askEntity.status)
                    Text(text = "申报时间：${askEntity.time}", fontSize = 10.sp, color = Color.Gray)
                    Spacer(modifier = Modifier.height(20.dp))
                    Text(text = if (askEntity.status == "已提交") "审批中" else askEntity.status)
                    Text(
                        text = "审批时间：${askEntity.comTime}",
                        fontSize = 10.sp,
                        color = Color.Gray
                    )
                }
            }
        }
    }
}

@Preview
@Composable
fun AskDetailPreview() {
    AskDetailPage()
}

